package view.hero
{
import flash.display.MovieClip;
import flash.events.Event;

import framework.view.components.container.RepeaterRenderProxy;

/**
 * HeroEquipSelectionItemRender
 * @author jliang
 *
 */
public class HeroEquipSelectionItemRenderProxy extends RepeaterRenderProxy
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function HeroEquipSelectionItemRenderProxy()
	{
		super();
	}
	//==========================================================================
	//  Variables
	//==========================================================================
	protected function get avatar():HeroItemRenderProxy
	{
		return proxys["avatar"];
	}
	
	protected function get equipment():HeroEquipSelectionEquipmentItemRenderProxy
	{
		return proxys["equipment"];
	}
	//==========================================================================
	//  Overridden methods: HeroEquipSelectionItemRender
	//==========================================================================
	protected var _data:Object;
	
	override public function set data(value:*):void
	{
		_data = value;
		
		avatar.data = data.avatar;		
		equipment.data = data.equipment;
	}
	
	override public function get data():*
	{
		return _data;
	}
	
	override public function set selected(value:Boolean):void
	{
		avatar.selected = value;
	}
	
	override public function get selected():Boolean
	{
		return avatar.selected;
	}	
	
	override protected function get proxyMapping():Array
	{
		return [ 
			{ skin:"avatar", classRef: HeroItemRenderProxy, id:"avatar" },
			{ skin:"equipment", classRef: HeroEquipSelectionEquipmentItemRenderProxy , id:"equipment" }
		];
	}
	
	override public function parse(target:MovieClip):void
	{
		super.parse(target);
		
		skin.avatar.addEventListener(Event.SELECT, selectHandler, false, 5);
	}
	
	override public function dispose():void
	{
		_data = null;
		if (skin)
		{
			skin.avatar.removeEventListener(Event.SELECT, selectHandler);
		}
		super.dispose();
	}
	
	protected function selectHandler(event:Event):void
	{
		event.stopImmediatePropagation();
		
		this.select();
	}
}
}



